package com.probox.modules.controller.wechat;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.wechat.WechatMessageList;
import com.probox.common.entity.service.wechat.IWechatMessageListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 消息发送记录Controller
 *
 * @author usoft
 * @date 2021-08-16
 */
@RestController
@RequestMapping("/wechat/wechatMessage")
public class WechatMessageListController extends BaseController {
    @Autowired
    private IWechatMessageListService wechatMessageListService;

    /**
     * 查询消息发送记录列表
     */
    @PreAuthorize(hasPermi = "wechat:wechatMessage:list")
    @GetMapping("/list")
    public TableDataInfo list(WechatMessageList wechatMessageList) {
        startPage();
        List<WechatMessageList> list = wechatMessageListService.queryList(wechatMessageList);
        return getDataTable(list);
    }

    /**
     * 导出消息发送记录列表
     */
    @PreAuthorize(hasPermi = "wechat:wechatMessage:export")
    @Log(title = "消息发送记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WechatMessageList wechatMessageList) throws IOException {
        List<WechatMessageList> list = wechatMessageListService.queryList(wechatMessageList);
        ExcelUtil<WechatMessageList> util = new ExcelUtil<WechatMessageList>(WechatMessageList.class);
        util.exportExcel(response, list, "消息发送记录数据");
    }

    /**
     * 获取消息发送记录详细信息
     */
    @PreAuthorize(hasPermi = "wechat:wechatMessage:query")
    @GetMapping(value = "/{messageUid}")
    public AjaxResult getInfo(@PathVariable("messageUid") Long messageUid) {
        return AjaxResult.success(wechatMessageListService.selectWechatMessageListById(messageUid));
    }

    /**
     * 新增消息发送记录
     */
    @PreAuthorize(hasPermi = "wechat:wechatMessage:add")
    @Log(title = "消息发送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WechatMessageList wechatMessageList) {
        return toAjax(wechatMessageListService.insertWechatMessageList(wechatMessageList));
    }

    /**
     * 修改消息发送记录
     */
    @PreAuthorize(hasPermi = "wechat:wechatMessage:edit")
    @Log(title = "消息发送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WechatMessageList wechatMessageList) {
        return toAjax(wechatMessageListService.updateWechatMessageList(wechatMessageList));
    }

    /**
     * 删除消息发送记录
     */
    @PreAuthorize(hasPermi = "wechat:wechatMessage:remove")
    @Log(title = "消息发送记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{messageUids}")
    public AjaxResult remove(@PathVariable Long[] messageUids) {
        return toAjax(wechatMessageListService.deleteWechatMessageListByIds(messageUids));
    }
}
